package models

import "gorm.io/datatypes"

type Admin struct {
	BaseModel
	Username string `gorm:"type:varchar(50);uniqueIndex;not null"`
	Password string `gorm:"type:varchar(255);not null"`
	RealName string `gorm:"type:varchar(50)"`
	Mobile   string `gorm:"type:varchar(20);uniqueIndex"`
	Email    string `gorm:"type:varchar(100);uniqueIndex"`
	Avatar   string `gorm:"type:varchar(255)"`           // 头像URL
	Status   int    `gorm:"type:smallint;default:10"`    // 10:启用, 20:禁用
	RoleId   uint   `gorm:"type:int;not null;default:0"` // 角色ID
}

type AdminRole struct {
	BaseModel
	Name        string         `gorm:"type:varchar(50);uniqueIndex;not null"`
	Desc        string         `gorm:"type:varchar(100)"`
	Status      int            `gorm:"type:smallint;default:10"` // 10:启用, 20:禁用
	Permissions datatypes.JSON `gorm:"type:jsonb"`               //
}

type Permission struct {
	BaseModel
	Name       string         `gorm:"type:varchar(50);not null"`
	Type       uint           `gorm:"type:int;default:1;"`
	Sort       int            `gorm:"type:int;default:0"`
	Redirect   string         `gorm:"type:varchar(150);not null;default:''"`
	Perm       string         `gorm:"type:varchar(100);uniqueIndex;not null"` // 格式: "module:action", 如 "product:view"
	RouteName  string         `gorm:"type:varchar(100)"`                      // 前端路由路径
	RoutePath  string         `gorm:"type:varchar(100)"`                      // 前端路由路径
	Component  string         `gorm:"type:varchar(100)"`                      // 前端组件路径
	Icon       string         `gorm:"type:varchar(50);default:'';"`           // 前端组件路径
	ParentID   uint           `gorm:"index"`
	Hidden     bool           `gorm:"type:boolean;default:false"`
	AlwaysShow bool           `gorm:"type:boolean;default:true"`
	KeepAlive  bool           `gorm:"type:boolean;default:false"`
	Params     datatypes.JSON `gorm:"type:jsonb"`
}
